<template>
  <div class="goodsFenleiIndex">
    <el-card class="box-card">
      <!-- one------------------------------------------------------- -->
      <div slot="header" class="clearfix header">
        <span>创建商品属性</span>
        <el-button type="primary" round @click="createFn">创建</el-button>
      </div>
      <!-- -------------------------------------------------------------- -->

      <el-table :data="tableData" style="width: 100%" height="250" stripe>
        <el-table-column fixed prop="cat_id" label="编号" width="150">
        </el-table-column>
        <el-table-column prop="cat_name" label="分类名称" width="120">
        </el-table-column>
        <el-table-column prop="level" label="分类层级">
          <template slot-scope="item">
            <el-tag v-bind:type="item.row.level + ''">
              {{ item.row.level }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagenum"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pagetotal"
      >
      </el-pagination>
      <!-- /分页 -->
    </el-card>
  </div>
</template>

<script>
import { getFenleiIndex } from "@/api";
export default {
  created() {
    this.initData();
  },
  methods: {
    //请求接口渲染页面
    initData() {
      getFenleiIndex({
        pagenum: this.pagenum,
        pagesize: this.pagesize
      }).then(res => {
        // console.log(res)
        this.tableData = res.data.list;
        this.pagetotal = parseInt(res.data.total);
      });
    },

    //创建按钮
    createFn() {
      this.$router.push({ path: "/goods/cate/create" });
    },
    // 切换每页条数
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pagesize = val;
      this.initData();
    },
    // 切换分页
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.pagenum = val;
      this.initData();
    }
  },

  data() {
    return {
      // 分页
      level: 3,
      pagenum: 1,
      pagesize: 5,
      pagetotal: 0,

      tableData: []
    };
  }
};
</script>

<style lang="scss" scoped>
.goodsFenleiIndex {
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
